<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    /* 
        reg.exec()
          - 返回一个数组，其中包含匹配的结果。如果没有匹配的结果，则返回 null。
    */
    let str = "abcadcaecagc";
    //提取出 str中符合格式的内容
    //g  表示全局匹配，即找到所有匹配的结果
    //i  表示忽略大小写

    let reg1 = /a([a-z])c/g; // 只有加了g，全局匹配， reg1的lastIndex才会增加。   ()进行分组。
    console.log(reg1.exec(str));
    console.log(reg1.exec(str));
    console.log(reg1.exec(str));
    console.log(reg1.lastIndex); // 9
    console.log(reg1.exec(str));
    console.log(reg1.exec(str)); // null
    let str1 = "fdsfds153367435325f";
    let regGetNum = /\d+/g;

    let res = regGetNum.exec(str1);
    while (regGetNum.lastIndex) {
      console.log(regGetNum.exec(str1));
    }

    console.log(str1.match(/\d+/g));
    let phoneNum = "sffdsdsf15536532321fdsfa15573569012ffdsf13457345632";
    let filterStr = phoneNum.match(/\d{11}/g);

    for (var i = 0; i < filterStr.length; i++) {
      console.log(/\d{3}(\d+)\d{4}/.exec(filterStr[i]));
      filterStr[i] = filterStr[i].replace(
        /\d{3}(\d+)\d{4}/.exec(filterStr[i])[1],
        "****"
      );
    }
    console.log(filterStr);
  </script>
</html>
